﻿using System;
using Xunit;

namespace Unity.String.Tests
{
    public class FormatParserTest
    {
        [Fact]
        public void ScanFormatStringTest()
        {
            string testStringValue = "Hello, {username}. Welcome";
            
            for (int testIndex = 0; testIndex < testStringValue.Length; testIndex++)
            {
                // FormatParser.ScanFormatString(testStringValue, ref testIndex);    
            }
            
        }

        [Fact]
        public void ParseTest()
        {
            string testFormatValue = "{0}";
            int testIndex = 0;
            FormatParser.Parse(testFormatValue, testIndex);

            string testEmptyFormatValue = "";
            int testEmptyIndex = -1;
            
            Assert.Throws<IndexOutOfRangeException>(() => { FormatParser.Parse(testEmptyFormatValue, testIndex); });
            
            Assert.Throws<ArgumentException>(() => { FormatParser.Parse(testEmptyFormatValue, testEmptyIndex); });
            
            Assert.Throws<ArgumentException>(() => { FormatParser.Parse(testFormatValue, testEmptyIndex); });

            string testEqualSizeFormatValue = " {{";
            int testEqualSizeIndex = 1;
            Assert.Throws<FormatException>(() => { FormatParser.Parse(testEqualSizeFormatValue, testEqualSizeIndex); });
            
            Assert.Throws<FormatException>(() =>
            {
                FormatParser.Parse(testEqualSizeFormatValue, testEqualSizeIndex - 1);
            });

            string testFormatWithExtraLimitArguments =
                "{20}";
            Assert.Throws<FormatException>(() => { FormatParser.Parse(testFormatWithExtraLimitArguments, 0); });

            string testFormatStartWithComma = " , {-0}";
            Assert.Throws<FormatException>(() => { FormatParser.Parse(testFormatStartWithComma, testIndex); });
            
            string testFormatCase1 = "{0},   ";
           
                FormatParser.Parse(testFormatCase1, testIndex);
           
            
            string testFormatCase2 = "{0},   -";
            
                FormatParser.Parse(testFormatCase2, testIndex);
            
            
            string testFormatCase3 = "{0},  -2";
            
                FormatParser.Parse(testFormatCase3, testIndex);
            
            
            string testFormatCase4 = "{0},  -a";
            
                FormatParser.Parse(testFormatCase4, testIndex);
            
            
            string testFormatCase5 = "{0},  -2  :";
           
                FormatParser.Parse(testFormatCase5, testIndex);
            
            
            string testFormatCase6 = "{0},  -2  :{";
            
                FormatParser.Parse(testFormatCase6, testIndex);
            
        }

    }
}